<?php
use lib\controller\Controller;
use lib\dao\query\Query;
use lib\image\SimpleImage;
use lib\dao\query\QueryAnd;
use lib\factory\Factory;
use lib\factory\FactoryModel;

class AficheController extends Controller{
	
	public function init(){
		$this->Model = false;
		parent::init();
	}
	
	public function index(){
            try{
                $token = $this->getParam('token');
                if(is_null($token)){
                    throw new Exception($this->Tr->_('invalid_token'));
                }
                
                $Evento = Factory::create(FactoryModel::getInstance(), 'Evento');
                $Q = new Query($Evento);
                $Q->add(new QueryAnd('e.token',$token));
                $evento = $Evento->detalleEvento($Q);

                if(empty($evento)){
                        throw new \Exception('No exite evento para ese token');
                }
                $this->View->assign('evento', $evento);
                
                //Levantamos el detalle de cada sector 
                $QS = new Query($Evento);
                $QS->add(new QueryAnd('evento_id',$evento[0]['id']));
                $this->View->assign('detalleSectores', $Evento->detalleXSector($QS));
                
            }catch (\Exception $e){
                $this->View->assign('msg', array('error', $e->getMessage()));
            }
            $this->View->layout = 'frontend';
            $this->View->display();
	}
        
}